/*
 * 文件名：CompanyController.java
 * 版权：Copyright 2007-2016 517na Tech. Co. Ltd. All Rights Reserved. 
 * 描述： CompanyController.java
 * 修改人：yanshu
 * 修改时间：2016年1月12日
 * 修改内容：新增
 */
package com.feichuang.chineseWoodCarving.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.better517na.commons.Response;
import com.better517na.commons.StatusCode;
import com.feichuang.chineseWoodCarving.business.ICompanyBusiness;
import com.feichuang.chineseWoodCarving.model.MCompanyVo;
import com.feichuang.chineseWoodCarving.model.MPagerRequestVo;
import com.feichuang.chineseWoodCarving.model.MPagerResultVo;
import com.google.gson.Gson;

/**
 * TODO 添加类的一句话简单描述.
 * <p>
 * TODO 详细描述
 * <p>
 * TODO 示例代码
 * 
 * <pre>
 * </pre>
 * 
 * @author yanshu
 */
@Controller
@RequestMapping(value = "/company")
public class CompanyController {
    /**
     * @业务处理入口
     */
    @Resource(name = "companyBusiness")
    private ICompanyBusiness companyBusiness;

    /**
     * 
     * TODO 企业信息模糊查询，根据企业名称作为默认搜索.
     * 
     * @param request
     * @param response
     * @param param
     *            企业名称
     * @param type
     * @return
     */
    @RequestMapping(value = "/fuzzyQuerCompany", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String fuzzyQuerCompany(HttpServletRequest request, HttpServletResponse response, String param, String type, int currentpage, int size) {
        Gson gson = new Gson();
        Response<MPagerResultVo<MCompanyVo>> res = new Response<MPagerResultVo<MCompanyVo>>();
        try {
            MCompanyVo companyVo = new MCompanyVo();
            companyVo.setEnterpriseName(param);
            MPagerResultVo<MCompanyVo> pageRes = companyBusiness.selectMCompanyVoFuzzyQuer(companyVo, currentpage, size);
            if (null != pageRes && pageRes.getTotalCount() > 0) {
                res.setContent(pageRes);
            }
            return gson.toJson(res);
        } catch (Exception e) {
            return gson.toJson(res);
        }
    }

    /**
     * 
     * TODO 企业信息分页查询，根据企业所在省份作为默认搜索.
     * 
     * @param request
     * @param response
     * @param param
     *            分页查询参数，包括省份、分页大小，起始页等
     * @param type
     * @return
     */
    @RequestMapping(value = "/pageQuerCompany", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String pageQuerCompany(HttpServletRequest request, HttpServletResponse response, String param, String type) {
        Response<MPagerResultVo<MCompanyVo>> res = new Response<MPagerResultVo<MCompanyVo>>();
        Gson gson = new Gson();
        try {
            MPagerRequestVo<MCompanyVo> pageResquestVo = gson.fromJson(param, MPagerRequestVo.class);
            MPagerResultVo<MCompanyVo> pageRes = companyBusiness.selectMCompanyInfoForPage(pageResquestVo);
            res.setCode(StatusCode.SUCCESS);
            if (null != pageRes && pageRes.getTotalCount() > 0) {
                res.setContent(pageRes);
            }
        } catch (Exception e) {
            res.setCode(StatusCode.ERROR);
            res.setMessage("风速过大");
        }
        return gson.toJson(res);
    }
}
